package org.tissou.client.Services;

import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeListener;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.tissou.client.Panel_Premier.Panel_Premier;

/**
 * Created by IntelliJ IDEA.
 * User: Claire
 * Date: 16-Mar-2009
 * Time: 22:44:24
 * To change this template use File | Settings | File Templates.
 */
public class ArbreDeComptes extends Tree {


  private AsyncCallback<ProprietaireInfos> chargeageCallback = new AsyncCallback<ProprietaireInfos>() {

    public void onFailure(Throwable caught) {
      addItem("Erreur mec.");
    }

    public void onSuccess(ProprietaireInfos result) {
      addItem(result.donneLArbreDesComptes());
    }
  };

  public ArbreDeComptes(String nomProprietaire) {
    super();
    chargerLeProprietaire(nomProprietaire);

  }

  private void chargerLeProprietaire(String nomProprietaire) {
    ProprioService.App.getInstance().donneProprio(nomProprietaire,chargeageCallback);
  }

  public Compte donneLeCompteSelectionne() throws MonException{
    try {
      return (Compte) this.getSelectedItem().getUserObject();
    } catch (NullPointerException e){
      throw new MonException("Tu n'as pas selectionne de compte !", e);
    }
  }

  public MonnaieInfos donneLaMonnaieDuCompteSelectionne()throws MonException {
    return donneLeCompteSelectionne().getMonnaie();
  }

  

}
